import org.sca.middle.cmpe.user.Security
import org.sca.middle.cmpe.user.SecurityFactory
import org.sca.middle.cmpe.dto.Fighter
import org.sca.middle.cmpe.db.FighterDAO
import com.google.appengine.api.datastore.Entity
import com.google.appengine.api.blobstore.BlobInfo
import com.google.appengine.api.blobstore.BlobKey
import org.sca.middle.cmpe.dto.FighterListItem
import org.sca.middle.cmpe.dto.Authorization
import org.sca.middle.cmpe.utils.MarshalUtils
import org.sca.middle.cmpe.common.*
import com.google.appengine.api.datastore.*
import static com.google.appengine.api.datastore.FetchOptions.Builder.*



def scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Afonlyn (Shire)"
scaGroup.groupLocation = "Constellation"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Cúil Choluim (Shire)"
scaGroup.groupLocation = "Constellation"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Dragon's Vale (Shire)"
scaGroup.groupLocation = "Constellation"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Greyhope (Shire)"
scaGroup.groupLocation = "Constellation"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Mynydd Seren (Shire)"
scaGroup.groupLocation = "Constellation"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Narrental (Shire)"
scaGroup.groupLocation = "Constellation"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Qal`at Ja`far (Shire)"
scaGroup.groupLocation = "Constellation"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Rivenstar (Barony)"
scaGroup.groupLocation = "Constellation"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Riviere Constelle (Shire)"
scaGroup.groupLocation = "Constellation"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Shadowed Stars (Shire)"
scaGroup.groupLocation = "Constellation"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Steren Codha (Shire)"
scaGroup.groupLocation = "Constellation"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Sternfeld (Barony)"
scaGroup.groupLocation = "Constellation"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "White Waters (Barony)"
scaGroup.groupLocation = "Constellation"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Ayreton (Barony)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Foxvale (Canton of Ayreton)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Grey Gargoyles (Canton of Ayreton)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Rokkehealden (Canton of Ayreton)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Tree-Girt-Sea (Canton of Ayreton)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Vanished Wood (Canton of Ayreton)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Baile na Scolairi (Shire)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Blackhawk (Shire)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Carraig Ban (Barony)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Dark River (Shire)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Illiton (Barony)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Lochmorrow (Canton of Illiton)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Athelington (Incipient Canton of Illiton)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Ravenslake (Shire)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Saint Carol on the Moor (College)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Shattered Crystal (Barony)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Swordcliff (Shire)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Wurm Wald (Shire)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Black Rock Forge (Incipient Canton)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Runvidrstad (Incipient Shire)"
scaGroup.groupLocation = "Midlands"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Brendoken (Barony)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Alderford (Canton of Brendoken)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Gwyntarian (Canton of Brendoken)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Thistle (Canton of Brendoken)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Three Towers (Canton of Brendoken)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Castell Gwent (Shire)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Cleftlands (Barony)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Eastwatch (Shire)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Falcon's Quarry (Shire)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Middle Marches (Barony)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Dernehealde (Shire of Middle Marches)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Gleann Iaruinn (Canton of Middle Marches)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

def mugmortGroup = new Entity ("ScaGroup")
mugmortGroup.groupName = "Mugmort (Shire of Middle Marches)"
mugmortGroup.groupLocation = "North Oaken"
mugmortGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Tirnewydd (Shire of Middle Marches)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Oakford (Shire)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Red Spears (Barony)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Catteden (Canton of Red Spears)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Hróðgeirsfjörðr (Canton of Red Spears)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Marshes, Marche of the (Canton of Red Spears)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Rivenvale (Shire)"
scaGroup.groupLocation = "North Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Altenberg (Shire)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Andelcrag (Barony)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Dun Traigh (Canton of Andelcrag)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Nordheim (Canton of Andelcrag)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Rimsholt (Canton of Andelcrag)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Three Hills (Canton of Andelcrag)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Three Walls (Canton of Andelcrag)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Westmere (Canton of Andelcrag)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Cynnabar (Barony)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Donnershafen (Barony)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Fearann na Criche (Shire)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Northwoods (Barony)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Ealdnordwuda (Canton of Northwoods)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Hawkland Moor (Riding of Northwoods)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Iron Oak (Incipient Canton of Northwoods)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Wealdlake (Canton of Northwoods)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Roaring Wastes (Barony)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Brackendelve (Canton of Roaring Wastes)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Starleaf Gate (Shire)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Stormvale (Shire)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Talonval (Shire)"
scaGroup.groupLocation = "Pentamere"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Aurea Ripae (Shire)"
scaGroup.groupLocation = "South Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Dragonsmark (Shire)"
scaGroup.groupLocation = "South Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Okenshield (Shire)"
scaGroup.groupLocation = "South Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Fenix (Barony)"
scaGroup.groupLocation = "South Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Flame (Barony)"
scaGroup.groupLocation = "South Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Flaming Gryphon (Barony)"
scaGroup.groupLocation = "South Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Havenholde (Canton of Flaming Gryphon)"
scaGroup.groupLocation = "South Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Hawkes Keye (Canton of Flaming Gryphon)"
scaGroup.groupLocation = "South Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Norborough (Canton of Flaming Gryphon)"
scaGroup.groupLocation = "South Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Unicorn (Canton of Flaming Gryphon)"
scaGroup.groupLocation = "South Oaken"
scaGroup.save()

scaGroup = new Entity ("ScaGroup")
scaGroup.groupName = "Winged Hills (Canton of Flaming Gryphon)"
scaGroup.groupLocation = "South Oaken"
scaGroup.save()


def i = 0
def acwsh = new Entity("AuthType")
acwsh.code = "AC:WSH"
acwsh.description = "Weapon and Shield"
acwsh.orderValue = ++i
acwsh.save()

def actw = new Entity("AuthType")
actw.code = "AC:TW"
actw.description = "Two Weapons"
actw.orderValue = ++i
actw.save()

def acgw = new Entity("AuthType")
acgw.code = "AC:GW"
acgw.description = "Great Weapon"
acgw.orderValue = ++i
acgw.save()

def acpa = new Entity("AuthType")
acpa.code = "AC:PA"
acpa.description = "Polearm"
acpa.orderValue = ++i
acpa.save()

def acsp = new Entity("AuthType")
acsp.code = "AC:SP"
acsp.description = "Spear"
acsp.orderValue = ++i
acsp.save()

def acca = new Entity("AuthType")
acca.code = "AC:CA"
acca.description = "Combat Archery"
acca.orderValue = ++i
acca.save()

def acse = new Entity("AuthType")
acse.code = "AC:SE"
acse.description = "Siege Engineer"
acse.orderValue = ++i
acse.save()

def acmarshal = new Entity("AuthType")
acmarshal.code = "AC:Marshal"
acmarshal.description = "Armored Combat Marshal"
acmarshal.orderValue = ++i
acmarshal.save()

def camarshal = new Entity("AuthType")
camarshal.code = "CA:Marshal"
camarshal.description = "Combat Archery Marshal"
camarshal.orderValue = ++i
camarshal.save()

def semarshal = new Entity("AuthType")
semarshal.code = "SE:Marshal"
semarshal.description = "Siege Marshal"
semarshal.orderValue = ++i
semarshal.save()

def rpsr = new Entity("AuthType")
rpsr.code = "RP:SR"
rpsr.description = "Single Rapier"
rpsr.orderValue = ++i
rpsr.save()

def rpdg = new Entity("AuthType")
rpdg.code = "RP:DG"
rpdg.description = "Dagger"
rpdg.orderValue = ++i
rpdg.save()

def rppd = new Entity("AuthType")
rppd.code = "RP:PD"
rppd.description = "Parry Device"
rppd.orderValue = ++i
rppd.save()

def rpcs = new Entity("AuthType")
rpcs.code = "RP:CS"
rpcs.description = "Case"
rpcs.orderValue = ++i
rpcs.save()

def rpep = new Entity("AuthType")
rpep.code = "RP:EP"
rpep.description = "Epee"
rpep.orderValue = ++i
rpep.save()

def rpct = new Entity("AuthType")
rpct.code = "RP:CT"
rpct.description = "Cut and Thrust"
rpct.orderValue = ++i
rpct.save()

def rpMarshal = new Entity("AuthType")
rpMarshal.code = "RP:Marshal"
rpMarshal.description = "Rapier Marshal"
rpMarshal.orderValue = ++i
rpMarshal.save()

def ctMarshal = new Entity("AuthType")
ctMarshal.code = "CT:Marshal"
ctMarshal.description = "Cut and Thrust Marshal"
ctMarshal.orderValue = ++i
ctMarshal.save()

def ytd1 = new Entity("AuthType")
ytd1.code = "YT:D1"
ytd1.description = "Youth Div 1,2"
ytd1.orderValue = ++i
ytd1.save()

def ytd3 = new Entity("AuthType")
ytd3.code = "YT:D3"
ytd3.description = "Youth Div 3"
ytd3.orderValue = ++i
ytd3.save()

def ytmarshal = new Entity("AuthType")
ytmarshal.code = "YT:Marshal"
ytmarshal.description = "Youth Marshal"
ytmarshal.orderValue = ++i
ytmarshal.save()

def eqgr = new Entity("AuthType")
eqgr.code = "EQ:GR"
eqgr.description = "General Riding"
eqgr.orderValue = ++i
eqgr.save()

def eqmg = new Entity("AuthType")
eqmg.code = "EQ:MG"
eqmg.description = "Mounted Game"
eqmg.orderValue = ++i
eqmg.save()

def eqac = new Entity("AuthType")
eqac.code = "EQ:AC"
eqac.description = "Armored Combat"
eqac.orderValue = ++i
eqac.save()

def eqcc = new Entity("AuthType")
eqcc.code = "EQ:CC"
eqcc.description = "Crest Combat"
eqcc.orderValue = ++i
eqcc.save()

def eqdr = new Entity("AuthType")
eqdr.code = "EQ:DR"
eqdr.description = "Driving"
eqdr.orderValue = ++i
eqdr.save()

def eqma = new Entity("AuthType")
eqma.code = "EQ:MA"
eqma.description = "Mounted Archery"
eqma.orderValue = ++i
eqma.save()

def eqfj = new Entity("AuthType")
eqfj.code = "EQ:FJ"
eqfj.description = "Lgt Foam Joust"
eqfj.orderValue = ++i
eqfj.save()

def eqmarshal = new Entity("AuthType")
eqmarshal.code = "EQ:Marshal"
eqmarshal.description = "Equestrian Marshal"
eqmarshal.orderValue = ++i
eqmarshal.save()

def armarshal = new Entity("AuthType")
armarshal.code = "AR:Marshal"
armarshal.description = "Archery Marshal"
armarshal.orderValue = ++i
armarshal.save()

def twmarshal = new Entity("AuthType")
twmarshal.code = "TW:Marshal"
twmarshal.description = "Thrown Weapons Marshal"
twmarshal.orderValue = ++i
twmarshal.save()

def json = """
"""

namespace.of("system") {
	def name = "middle.validStart"

	Entity sysTable = new Entity("properties")
	sysTable.name = name
	sysTable.property = "01/01/2014"

	sysTable.save()

	name = "middle.validEnd"

	sysTable = new Entity("properties")
	sysTable.name = name
	sysTable.property = "12/31/2018"

	sysTable.save()

	sysTable = new Entity("properties")
	sysTable.name = "middle.earlmarshal.email"
	sysTable.property = "earlmarshal@midrealm.org"

	sysTable.save()

	sysTable = new Entity("properties")
	sysTable.name = "middle.calonsteel.email"
	sysTable.property = "calonsteel@test.com"

	sysTable.save()

	sysTable = new Entity("properties")
	sysTable.name = "middle.central.email"
	sysTable.property = "centraldeputy@test.com"

	sysTable.save()

	sysTable = new Entity("properties")
	sysTable.name = "middle.from.email"
	sysTable.property = "from@test.com"

	sysTable.save()
}

// add users
def fighter = new Entity("Fighter")
fighter.scaName = "Diccon de Reinport"
fighter.scaMemberNo = "34722"
fighter.membershipExpires = new Date(115, 7, 31)
fighter.modernName = "Kevin L Carlen"
fighter.dateOfBirth = new Date(66, 4, 2)
fighter.googleId = "kcarlen@insight.rr.com"
fighter.scaGroup = mugmortGroup.key
fighter.role = UserRoles.CARD_MARSHAL.toString()
fighter.status = "ACTIVE"
fighter.lastUpdated = new Date();

fighter.save()

def authEntity = new Entity("Authorization", fighter.key);
authEntity.authType = acse.key
authEntity.date = new Date()
authEntity.save()

authEntity = new Entity("Authorization", fighter.key);
authEntity.authType = semarshal.key
authEntity.date = new Date()
authEntity.save()

authEntity = new Entity("Authorization", fighter.key);
authEntity.authType = armarshal.key
authEntity.date = new Date()
authEntity.save()

def addressEntity = new Entity("Address", fighter.key)
addressEntity.address1 = "7243 Kirkdale Dr"
addressEntity.city = "Blacklick"
addressEntity.postalCode = "43004"
addressEntity.state = "OH"
addressEntity.type = "Home"
addressEntity.save()

def emailEntity = new Entity("Email", fighter.key)
emailEntity.emailAddress = "kcarlen@insight.rr.com"
emailEntity.type = "Home"
emailEntity.save()

def phoneEntity = new Entity("Phone", fighter.key)
phoneEntity.phoneNumber = "6148644361"
phoneEntity.type = "Home"
phoneEntity.save()


forward "/StoreDatabase.groovy"